package com.zenithmind.common.config;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.converter.MessageConverter;

/**
 * RocketMQ配置类
 */
@Configuration
public class RocketMQConfig {

    /**
     * 配置消息转换器
     * 用于将Java对象转换为消息格式
     */
    @Bean
    public MessageConverter messageConverter() {
        return new MappingJackson2MessageConverter();
    }
    
    /**
     * 配置RocketMQTemplate
     * 确保MQUtils可以正常注入RocketMQTemplate
     */
    @Bean
    @Primary
    public RocketMQTemplate rocketMQTemplate() {
        RocketMQTemplate template = new RocketMQTemplate();
        template.setMessageConverter(messageConverter());
        return template;
    }
} 